

<!--------------------------------------------黄笠煌------------------------------------------------------------------>
<template>
    <!--Form 组件提供了表单验证的功能，只需要通过 rules 属性传入约定的验证规则，并将 Form-Item 的 prop 属性设置为需校验的字段名即可-->
    <!--:model用来绑定对象ruleForm，v-model绑定表单元素和对象属性，rules用来绑定校验规则,其中prop绑定表单元素和对应校验规则-->
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <!--ref相当于该form表单的名字，即用于提交事件的Formname-->
      <el-form-item label="配送中心" prop="distributecentre">
        <el-input v-model="ruleForm.distributecentre"></el-input>
      </el-form-item>
      <el-form-item label="库房" prop="storage">
          <el-input v-model="ruleForm.storage"></el-input>
      </el-form-item>
      <el-form-item label="重量" prop="weight">
          <el-input v-model.number="ruleForm.weight" ></el-input><!--当验证的下类型为数字类型时需采用v-model.number绑定-->
      </el-form-item>
      <el-form-item label="体积" prop="volume">
          <el-input v-model.number="ruleForm.volume" ></el-input><!--当验证的下类型为数字类型时需采用v-model.number绑定-->
      </el-form-item>
      <el-form-item label="数量" prop="number">
          <el-input v-model.number="ruleForm.number" ></el-input><!--当验证的下类型为数字类型时需采用v-model.number绑定-->
      </el-form-item>

    <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>

    </el-form-item>
  </el-form>
</template>
<script>
    export default {
        data() {
            return {
                /*定义表单返回对象ruleForm*/
                ruleForm: {
                    distributecentre: '',
                    storage: '',
                    weight: '',
                    volume: '',
                    number:'',

                },
                /*校验规则*/
                rules: {
                    distributecentre: [
                        { required: true, message: '请输入配送中心', trigger: 'blur' },

                    ],
                    storage: [
                        { required: true, message: '请输入库房', trigger: 'blur' }
                    ],
                    weight: [
                        { required: true, message: '请输入重量', trigger: 'blur' },
                        {type:'number',message:'请输入数字',trigger:'blur'}
                    ],
                    volume: [
                        { required: true, message: '请输入体积', trigger: 'blur' },
                        {type:'number',message:'请输入数字',trigger:'blur'}
                    ],
                    number: [
                        { required: true, message: '请输入数量', trigger: 'blur' },
                        {type:'number',message:'请输入数字',trigger:'blur'}
                    ],

                }
            };
        },
        methods: {

            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        /*alert('submit!');*/
                        /*在此验证成功，将数据给后台*/
                        const _this=this
                        axios.post('http://localhost:8181/ruleAdd',this.ruleForm).then(function (resp) {
                            _this.$alert('条件添加成功！','消息',{//添加成功提示弹窗
                                confirmButtonText:'确定',
                                callback:action => {
                                    _this.$router.push('/Displayrule')//跳转到条件查询页面
                                }
                            })

                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    }
</script>